
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回复列表</title>
<style type="text/css">
#user_fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}

.fitem input {
	width: 160px;
}
</style>


<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/color.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/demo/demo.css">
<script type="text/javascript" src="jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>

</head>
<body >

<!-- <div class="tableFind">
     <p>
		<label>日期</label><input type="text" id="dd" class="easyui-datebox"
			style="width: 16%; height: 26px;" /> <label>状态</label><input
			id="id_foodType" name="" class="easyui-combobox" url="#"
			valueField="typeNo" textField="type" required="true" editable="false">

		<a id="btn" href="javascript:" class="easyui-linkbutton tableFindBut"
			data-options="iconCls:'icon-search'" onclick="obj.find()">查询</a>
		</p>
	</div> -->
	<table id="user_dg" class="easyui-datagrid" style="height: 470px;"
		url="${pageContext.request.contextPath}/admin/Reply/findAll.do"
		toolbar="#user_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true"
		data-options="fit:false,border:false,pageSize:10,pageList:[10,20,30,40]">
		<thead>

			<!-- 管理表格-表头的修改 -->
			<tr>
			<th field="cb" checkbox="true" align="center"></th>
            <th field="replyNo" width="50" align="center">回复编号</th>
           <!--  <th field="commentNo" width="50" align="center">评论编号</th> -->
            <th field="commentNo" formatter="commentFormat" width="80">评论内容</th>
            
            <th field="replyContent" width="50" align="center">回复内容</th>
            <!-- <th field="userNo" width="50" align="center">会员编号</th> -->
            <th field="userNo" formatter="userFormat" width="80">发布作者</th>
            
            <th field="replyTime" width="50" align="center">回复时间</th>
            <th field="state" width="150" align="center">状态</th>
			</tr>
		</thead>
	</table>
	<div id="user_toolbar">
		<a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editReply()">编辑</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyReply()">删除</a>
	</div>
	<div id="user_dlg" class="easyui-dialog" style="padding: 10px 20px";
		closed="true" buttons="#user_dlg-buttons">
		<div class="ftitle">详细信息</div>
		<form id="user_fm" method="post" novalidate>
			<div class="fitem">
				<label>评论内容:</label>
				<input id="id_comment"  name="comment.commentNo" valueField="commentNo"
					textField="commContent" required="true" editable="false" url="${pageContext.request.contextPath}/admin/Comment/findList.do"
					class="easyui-combobox" readonly="readonly">
			</div>
			<div class="fitem">
				<label>回复内容:</label> <input name="replyContent" class="easyui-textbox">
			</div>
			<div class="fitem">
				<label>评论人:</label> <input id="id_userMessage"  name="userMessage.userNo" valueField="userNo"
					textField="userName" required="true" editable="false" url="${pageContext.request.contextPath}/UserMessage/findList.do"
					class="easyui-combobox" readonly="readonly">
			</div>
			<div class="fitem">
				<label>回复时间:</label> <input name="replyTime" class="easyui-datebox"
					validType="date" readonly="readonly">
			</div>
			<div class="fitem">
				<label>状态:</label> <input name="state" class="easyui-textbox">
			</div>
		</form>
	</div>
	<div id="user_dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="saveReply()" style="width: 90px">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#user_dlg').dialog('close')"
			style="width: 90px">取消</a>
	</div>
	<script type="text/javascript">
	
	function commentFormat(value, row, rowindex) {
		return row.comment.commContent;
	}
	
	function userFormat(value, row, rowindex) {
		return row.userMessage.userName;
	}
	 
	//重新设置easy ui的时间格式
	$.fn.datebox.defaults.formatter=function(date){
		var y=date.getFullYear();
		var m=date.getMonth()+1;
		var d=date.getDate();
		return y+'/'+m+'/'+d;
	}
	$.fn.datebox.defaults.parser=function(date){
		if(date){
			return new Date(date)
		}else{
			return new Date();
		}
	}
	
		var url;
		function newReply() {
			$('#user_dlg').dialog('open').dialog('setTitle', '新增');
			$('#user_fm').form('clear');//清除表单数据
			url = '${pageContext.request.contextPath}/admin/Reply/addReply.do';//新增调用的网址
		}
		function editReply() {
			var row = $('#user_dg').datagrid('getSelected');
			if (row) {
				$('#user_dlg').dialog('open').dialog('setTitle', '编辑');
				$('#user_fm').form('clear');//清除表单数据
				$('#user_fm').form('load', row);
				url = '${pageContext.request.contextPath}/admin/Reply/updateReply.do?replyNo=' + row.replyNo;
			}
			
			
			var commentdata = $('#id_comment').combobox('getData');
		    if(commentdata.length>0){
		    	//编辑窗口默认选中正在编辑的数据
			  $('#id_comment').combobox('select',row.comment.commentNo);
		    }; 
		    
		    var userMessagedata = $('#id_userMessage').combobox('getData');
		    if(userMessagedata.length>0){
			  $('#id_userMessage').combobox('select',row.userMessage.userNo);
		    }; 
			
			
		}
		function saveReply() {
			$('#user_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.errorMsg) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$('#user_dlg').dialog('close'); // close the dialog
						$('#user_dg').datagrid('reload'); // reload the user data
					}
				}
			});
		}
		function destroyReply() {
			var row = $('#user_dg').datagrid('getSelected');
			if (row) {
				$.messager.confirm('Confirm', '确定要删除吗?', function(r) {
					if (r) {
						//ajax调用--异步通信调用
						$.post('${pageContext.request.contextPath}/admin/Reply/deleteReply.do', {
							replyNo : row.replyNo
						}, function(result) {
							if (result.success) {
								$('#user_dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show({ // show error message
									title : 'Error',
									msg : result.errorMsg
								});
							}
						}, 'json');//回调函数
					}
				});
			}
		}
	</script>



</body>
</html>